package com.fs.decorator;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;

@Slf4j

public class RewriteRequestDecorator extends ServerHttpRequestDecorator
{
//    public static final String regexp = "/px-basesystem-logserver/(?<segment>.*)";

    public static final String replacement = "/$\\{segment}";

    public ServerHttpRequest delegate;

    public RewriteRequestDecorator(ServerHttpRequest delegate, String regexp) {
        super(delegate);
        log.info("======>重写Path");
        String rep = replacement.replace("$\\", "$");
        String path = delegate.getURI().getRawPath();  ///px-basesystem-logserver/beijing*/_search
        String newPath = path.replaceAll(regexp, rep);  //beijing*/_search
        ServerHttpRequest request = delegate.mutate().path(newPath).build();
        this.delegate = request;
    }

    @Override
    public ServerHttpRequest getDelegate() {
        return this.delegate;
    }
}
